package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.ProducePlan;
import com.example.demo.entity.PurchaseApplyOrder;
import com.example.demo.entity.PurchaseOrder;
import com.example.demo.service.ProducePlanService;
import com.example.demo.mapper.ProducePlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【produce_plan】的数据库操作Service实现
* @createDate 2025-01-08 17:50:36
*/
@Service
public class ProducePlanServiceImpl extends ServiceImpl<ProducePlanMapper, ProducePlan>
    implements ProducePlanService{
    @Autowired
    ProducePlanMapper producePlanMapper;

    @Override
    public ProducePlan selectByInfo(String userId, String trainingId, String planNumber,String orderNumber, String identifyCode) {
        QueryWrapper<ProducePlan> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(identifyCode!=null){
            queryWrapper.eq("identifyCode",identifyCode);
        }
        if(planNumber!=null){
            queryWrapper.eq("planNumber",planNumber);
        }
        if(orderNumber!=null){
            queryWrapper.eq("orderNumber",orderNumber);
        }
        queryWrapper.orderByDesc("planTime");
        List<ProducePlan> resultList = producePlanMapper.selectList(queryWrapper);
        if (!resultList.isEmpty()) {
            return resultList.get(0); // 这里返回结果列表的第一条记录
        } else {
            return null;
        }
    }

    @Override
    public Integer deleteById(Integer id) {
        return producePlanMapper.deleteById(id);
    }
}




